#include <iostream>
#include <queue>
#define LL long long
using namespace std;

const int kMaxN = 1e5 + 10;
LL f[kMaxN], sum[kMaxN];
int a[kMaxN];

LL DP(int n, int c) {
  deque<int> deq;
  LL s = 0;

  for (int i = 1; i <= n; i++) {
    s += a[i];
    for (; !deq.empty() && a[deq.back()] >= a[i]; deq.pop_back());
    deq.push_back(i);
    if (i >= c) {
      sum[i] = s - a[deq.front()];
      if (deq.front() + c - 1 == i) {
        deq.pop_front();
      }
      s -= a[i - c + 1];
    }
  }

  f[0] = 0;
  for (int i = 1; i <= n; i++) {
    f[i] = f[i - 1] + a[i];
    if (i - c >= 0) {
      f[i] = min(f[i], f[i - c] + sum[i]);
    }
  }
  return f[n];
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, c;

  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  cout << DP(n, c) << "\n";
  return 0;
}